home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / dsp / dspkgctr.z / dspkgctr / gcc / fixincludes < prev    next >
Text File  |  1992-06-08  |  4KB  |  155 lines

  1. #! /bin/sh
  2. # Install modified versions of certain ANSI-incompatible system header files
  3. # which are fixed to work correctly with ANSI C
  4. # and placed in a directory that GNU C will search.
  5. # This works properly on a Sun in system version 3.4;
  6. # for other versions, you had better check.
  7.  
  8. # Directory in which to store the results.
  9. LIB=${LIB-/usr/local/lib/gcc-include}
  10.  
  11. # Make sure it exists.
  12. mkdir $LIB > /dev/null 2>&1
  13.  
  14. # Determine whether this system has symbolic links.
  15. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  16.   rm -f $LIB/ShouldNotExist
  17.   LINKS=true
  18. else
  19.   LINKS=false
  20. fi
  21.  
  22. echo 'Making directories:'
  23. cd /usr/include
  24. if $LINKS; then
  25.   files=`ls -LR | sed -n s/:$//p`
  26. else
  27.   files=`find . -type d -print`
  28. fi
  29. for file in $files; do
  30.   mkdir $LIB/$file > /dev/null 2>&1
  31. done
  32.  
  33. # treetops gets an alternating list
  34. # of old directories to copy
  35. # and the new directories to copy to.
  36. treetops="/usr/include ${LIB}"
  37.  
  38. if $LINKS; then
  39.   echo 'Making internal symbolic directory links'
  40.   for file in $files; do
  41.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  42.     if [ "$dest" ]; then    
  43.       if expr $dest : '[^/.].*' > /dev/null; then
  44.     rmdir ${LIB}/$file > /dev/null 2>&1
  45.     rm -f ${LIB}/$file > /dev/null 2>&1
  46.     ln -s $dest ${LIB}/$file > /dev/null 2>&1
  47.       else                # dont make links outside /usr/include
  48.     treetops="$treetops $dest ${LIB}/$file"
  49.       fi
  50.     fi
  51.   done
  52. fi
  53.  
  54. set - $treetops
  55. while [ $# != 0 ]; do
  56.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  57.   echo "Finding header files in $1:"
  58.   cd /usr/include
  59.   cd $1
  60.   files=`find . -type f -print`
  61.   echo 'Checking header files:'
  62.   for file in $files; do
  63.     if egrep '[     ]_IO[A-Z]*\(|#define._IO|CTRL' $file > /dev/null; then
  64.       echo Fixing $file
  65.       if [ -r $file ]; then
  66.     cp $file $2/$file >/dev/null 2>&1    \
  67.     || echo "Can't copy $file"
  68.     chmod +w $2/$file
  69.     sed -e '
  70.                    :loop
  71.       /\\$/            N
  72.       /\\$/            b loop
  73.       /[     ]_IO[A-Z]*(/    s/(\(.\),/('\''\1'\'',/
  74.       /#define._IO/        s/'\''x'\''/x/g
  75.       /[^A-Z]CTRL[     ]*(/    s/\(.\))/'\''\1'\'')/
  76.       /#define.CTRL/        s/'\''c'\''/c/g
  77.     ' $2/$file > $2/$file.sed
  78.     mv $2/$file.sed $2/$file
  79.     if cmp $file $2/$file >/dev/null 2>&1; then
  80.        echo Deleting $2/$file\; no fixes were needed.
  81.        rm $2/$file
  82.     fi
  83.       fi
  84.     fi
  85.   done
  86.   shift; shift
  87. done
  88.  
  89. cd /usr/include
  90.  
  91. # Fix one other error in this file: a mismatched quote not inside a C comment.
  92. file=sundev/vuid_event.h
  93. if [ -r $file ]; then
  94.   if [ ! -r ${LIB}/$file ]; then
  95.     cp $file ${LIB}/$file >/dev/null 2>&1    \
  96.     || echo "Can't copy $file"
  97.     chmod +w ${LIB}/$file
  98.   fi
  99. fi
  100.  
  101. if [ -r ${LIB}/sundev/vuid_event.h ]; then
  102.   echo Fixing sundev/vuid_event.h comment
  103.   ex ${LIB}/sundev/vuid_event.h <<EOF
  104.   g/doesn't/s/doesn't/does not/
  105.   wq
  106. EOF
  107. fi
  108.  
  109. # Deal with yet another challenge, this in X11/Xmu.h
  110. file=X11/Xmu.h
  111. if [ -r $file ]; then
  112.   if [ ! -r ${LIB}/$file ]; then
  113.     mkdir ${LIB}/X11 2>&-
  114.     cp $file ${LIB}/$file >/dev/null 2>&1    \
  115.     || echo "Can't copy $file"
  116.     chmod +w ${LIB}/$file
  117.   fi
  118. fi
  119.  
  120. if [ -r ${LIB}/$file ]; then
  121.   echo Fixing $file sprintf declaration
  122.   ex ${LIB}/$file <<EOF
  123.   /^extern char \*    sprintf();$/c
  124. #ifndef __STDC__
  125. extern char *    sprintf();
  126. #endif /* !defined __STDC__ */
  127. .
  128.   wq
  129. EOF
  130. fi
  131.  
  132. echo 'Removing unneeded directories:'
  133. cd $LIB
  134. files=`find . -type d -print | sort -r`
  135. for file in $files; do
  136.   rmdir $LIB/$file > /dev/null 2>&1
  137. done
  138.  
  139. if $LINKS; then
  140.   echo 'Making internal symbolic non-directory links'
  141.   cd /usr/include
  142.   files=`find . -type l -print`
  143.   for file in $files; do
  144.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  145.     if expr "$dest" : '[^/].*' > /dev/null; then    
  146.       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
  147.       if [ -f $target ]; then
  148.         ln -s $dest ${LIB}/$file >/dev/null 2>&1
  149.       fi
  150.     fi
  151.   done
  152. fi
  153.  
  154. exit 0
  155.